﻿using System;
using System.Collections.Generic;

namespace EvoBoost.Core
{
	public class IndexedFeatureCombinationSplit : SplitBase<double[]>
	{
		private IndexedFeatureCombinationSplit(IEnumerable<ISplitParameterDescription> parameterDescriptions)
			: base(parameterDescriptions)
		{
		}

		public static IndexedFeatureCombinationSplit Create(int featureCount)
		{
			if (featureCount <= 0)
				throw new ArgumentOutOfRangeException("featureCount", "Feature count should be positive.");
			
			List<ISplitParameterDescription> parameterDesc = new List<ISplitParameterDescription>(featureCount);
			for (int i = 0; i < featureCount; ++i)
				parameterDesc.Add(new MinMaxTruncSplitParameterDescription(-1, 1, 200, 50));

			return new IndexedFeatureCombinationSplit(parameterDesc);
		}

		public override double Calculate(double[] sampleProperties, IList<double> parameterValues)
		{
			if (sampleProperties == null) throw new ArgumentNullException("sampleProperties");
			if (parameterValues == null) throw new ArgumentNullException("parameterValues");
			if (parameterValues.Count != sampleProperties.Length)
				throw new ArgumentException("Parameter values count should be the same as the sample property count.");

			double result = 0;
			for (int i = 0; i < sampleProperties.Length; ++i)
				result += sampleProperties[i] * parameterValues[i];

			return result;
		}
	}
}
